package cn.edu.hubu.hubusmartzoohouse.controller;

import cn.edu.hubu.hubusmartzoohouse.entity.Device;
import cn.edu.hubu.hubusmartzoohouse.mapper.DeviceMapper;
import cn.edu.hubu.hubusmartzoohouse.service.DeviceService;
import cn.edu.hubu.hubusmartzoohouse.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private DeviceMapper deviceMapper;

    @RequestMapping("/device/insert")
    public ResultVo insert(Device device){
        ResultVo vo = deviceService.insert(device);
        return vo;
    }

    @RequestMapping("/device/list")
    public ResultVo list(){
        ResultVo vo = deviceService.listDevice();
        return vo;
    }

    @RequestMapping("/device/delete")
    public ResultVo delete(Integer deviceId){
        ResultVo vo = deviceService.logicDeleteDevice(deviceId);
        return vo;
    }

    @RequestMapping("/device/get")
    public ResultVo get(Integer deviceId){
        ResultVo vo = deviceService.get(deviceId);
        return vo;
    }

    @RequestMapping("/device/update")
    public ResultVo updateDevice(Device device){
        ResultVo vo = deviceService.modifyDevice(device);
        return vo;
    }

    @RequestMapping("/device/searchById")
    public ResultVo searchDeviceById(Integer deviceId){
        ResultVo vo = deviceService.searchDeviceById(deviceId);
        return vo;
    }

    @RequestMapping("/device/searchByName")
    public ResultVo searchDeviceByName(String deviceName){
        ResultVo vo = deviceService.searchDeviceByName(deviceName);
        return vo;
    }
}
